package cn.otrue.patienthealthmanager.activity;


import java.util.HashMap;

import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.bean.TransferParameter;
import cn.otrue.patienthealthmanager.http.HttpCons;
import cn.otrue.patienthealthmanager.http.HttpServer;
import cn.otrue.patienthealthmanager.http.ServerHandler;
import cn.otrue.patienthealthmanager.utils.MyConst;

public class DocterActivitymianfeiwen extends BaseActivity {


	private EditText et_bingqing;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_dactor_zixun);
		intiView();
	}
	
	
	
	private void intiView() {
	
	et_bingqing = (EditText) findViewById(R.id.et_bingqing);
	initTitlBar();
	}



	public void initTitlBar() {
		TextView tv_title_back = (TextView) findViewById(R.id.tv_title_back);
		TextView tv_title_title = (TextView) findViewById(R.id.tv_title_title);
		TextView tv_title_other = (TextView) findViewById(R.id.tv_title_other);
		tv_title_other.setVisibility(View.VISIBLE);
		tv_title_other.setOnClickListener(this);
		tv_title_other.setText(getString(R.string.next));
		tv_title_back.setVisibility(View.VISIBLE);
		tv_title_back.setOnClickListener(this);
		tv_title_title.setText(getString(R.string.idea));
		
	}
	
	
	
	private Handler Handler = new ServerHandler() {
		@Override
		public void onSuccess(Bundle data, String state, String msg) {
			if (state.equals("001")) {
					finish();
				Toast.makeText(getApplicationContext(), msg, 0).show();
			} else {
			
				
				Toast.makeText(getApplicationContext(), msg, 0).show();

			}
		}

		@Override
		public void onFail(Bundle data, String state) {
		
			if (state.equals(HttpCons.STATE_EXCEPTION)) {
				// 代表进入状态STATE_EXCEPTION 网络异常
				Toast.makeText(DocterActivitymianfeiwen.this, "网络异常,请稍后重试",
						Toast.LENGTH_SHORT).show();
			} else if (state.equals(HttpCons.STATE_FORMAT_ERROR)) {
				// 代表进入STATE_FORMAT_ERROR(不是Json)
			} else {
				// 代表进入STATE_ANALYTICAL_ERROR(Json解析错误)

			}
		}
	};
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
	switch (v.getId()) {
	case R.id.tv_title_back:
		finish();
		break;
	case R.id.tv_title_other:
	
		 if (TextUtils.isEmpty(et_bingqing.getText().toString())){
			Toast.makeText(getApplicationContext(), "病情不能为空", 0).show();
		}else{
			HashMap<String, Object> map = new HashMap<String, Object>();
		
			map.put("content",et_bingqing.getText().toString() );
			TransferParameter parameter = new TransferParameter();
			parameter.setUsername(MyConst.getACCOUNT());
			parameter.setPassword("");
			parameter.setData(map);
			new HttpServer().post(HttpCons.insertFreeask,
					parameter, Handler);
			
			
		}
		break;
	default:
		break;
	} 
	}
	

}
